﻿using System;
using System.IO;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.IO {

    /// <summary>
    /// Rename
    /// move("c:\\hello.txt", "c:\\helloworld.txt");
    /// 
    /// Move
    /// move("c:\\hello.txt", "c:\\hello\\hello.txt");
    /// </summary>
    public class FileMoveNode : FuncNode {

        public FileMoveNode()
            : base() {
            base.Value = "move";
        }

        public override object Evaluate() {
            if (Parameters.Count < 2) {
                return "usage: move(from, to)\nreturns the new file name";
            }

            string newName = Parameters[0].Evaluate().ToString();
            string oldName = Parameters[1].Evaluate().ToString();
            File.Move(oldName, newName);

            return newName;
        }
    }
}
